package com.example.esquel_carpool.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.example.esquel_carpool.R;
import com.example.esquel_carpool.entity.home.ImagesBean;
import com.example.esquel_carpool.glideModule.GlideApp;

import java.util.ArrayList;
import java.util.List;

public class HomeImagesListAdapter extends RecyclerView.Adapter<HomeImagesListAdapter.ViewHolder>{
    private static final String TAG = "HomeImagesListAdapter";
    private List<ImagesBean> data = new ArrayList<>();

    private LayoutInflater mInflater;

    private Context context;

    public HomeImagesListAdapter(Context context, List<ImagesBean> data) {
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.context = context;
        if (data !=null){
            this.data = data;
        }
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = mInflater.inflate(R.layout.home_images_list_item, viewGroup, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
        ImagesBean imagesBean = data.get(i);
        String path = imagesBean.getPath();
        GlideApp.with(context).load(path).diskCacheStrategy(DiskCacheStrategy.ALL).centerCrop().into(viewHolder.imageView);
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.imageView);
        }
    }
}
